NAMESPACE_ENTER(CFX)

#include "ReShade/ioFX.cfg"

#if USE_ChromaticAberration == 1
//Chromatic Aberration for ReShade + Framework by Ioxa
//Version 0.3
#if USE_ChromaticAberration == 1

#define caBUFFER_WIDTH BUFFER_WIDTH*0.5
#define caBUFFER_HEIGHT BUFFER_HEIGHT*0.5

texture caBlurTex2Dping{ Width = caBUFFER_WIDTH; Height = caBUFFER_HEIGHT; Format = RGBA8; };
texture caBlurTex2Dpong{ Width = caBUFFER_WIDTH; Height = caBUFFER_HEIGHT; Format = RGBA8; };
texture CAScale{ Width = caBUFFER_WIDTH; Height = caBUFFER_HEIGHT; Format = RGBA8; };

sampler2D caBlurSamplerPing { Texture = caBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D caBlurSamplerPong { Texture = caBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D CAScaleSampler { Texture = CAScale; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};

#if Use_MotionBlurCA == 1 

#define mbBufferWidth BUFFER_WIDTH
#define mbBufferHeight BUFFER_HEIGHT

texture2D PreviousPreviousTex { Width = mbBufferWidth; Height = mbBufferHeight; Format = RGBA8; };
texture2D PreviousTex { Width = mbBufferWidth; Height = mbBufferHeight; Format = RGBA8; };
texture2D CurrentTex { Width = mbBufferWidth; Height = mbBufferHeight; Format = RGBA8; };

sampler2D PrevPrevSampler { Texture = PreviousPreviousTex; };
sampler2D PrevSampler { Texture = PreviousTex; };
sampler2D CurrentSampler { Texture = CurrentTex; };
#endif
#endif
	//#define CoefLuma_CA float3(0.333,0.333,0.333)
	#define CoefLuma_CA float3(0.2126, 0.7152, 0.0722)
			
void CA_Final(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD, out float3 Chro : SV_Target0, out float3 Chro2 : SV_Target1)
{
		/*
		float2 BLUR_CENTER = float2(0.5, 0.5); // center of the blur
		float BLUR_START = 1; // blur offset
		float BLUR_WIDTH = -0.018; // blur size
		float2 center = texcoord;
		center -= BLUR_CENTER;
		//center *= float2((RFX_pixelSize.y / RFX_pixelSize.x),CA_LensShape);
		*/
		
			float2 distance_xy = texcoord - float2(0.5,0.5);
			float2 center = distance_xy;
			distance_xy *= float2((RFX_pixelSize.y / RFX_pixelSize.x),CA_LensShape);
			float Concave = dot(distance_xy,distance_xy)*CA_LensFocus;
			Concave = (1.0 + pow(Concave,0.25) * -1.00);
			Concave = 2 - ((Concave) * (0.01));
			
			float2 Coords = (Concave)*(center.xy*0.5); 
		
			#define CASampler RFX_backbufferColor
				
	#if CA_Color == 0	
		#if CA_Width == 0
			/*
			Chro = (tex2D(CASampler,(center * (BLUR_START + BLUR_WIDTH * 0.25) + BLUR_CENTER))).rgb*float3(0.8,0.0,-0.2805);
			Chro += (tex2D(CASampler,center * (BLUR_START + (BLUR_WIDTH*0.5) * 0.25) + BLUR_CENTER)).rgb*float3(0.0,0.25,-0.2805);
			
			Chro2 = (tex2D(CASampler,center * (BLUR_START - (BLUR_WIDTH*0.75) * 0.25) + BLUR_CENTER)).rgb*float3(0.0,0.0,1.0);
			Chro2 += (tex2D(CASampler,center * (BLUR_START - (BLUR_WIDTH*0.5) * 0.25) + BLUR_CENTER)).rgb*float3(0.0,0.25,0.0);
			Chro2 += (tex2D(CASampler,center * (BLUR_START - BLUR_WIDTH * 0.25) + BLUR_CENTER)).rgb*float3(0.2,0.0,0.561);
			*/
			
			Chro = (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(0.8,0.0,0.0));
			Chro += (tex2D(CASampler,(Coords*0.999) + 0.5).rgb*float3(0.0,0.25,0.0));
			
			Chro2 = (tex2D(CASampler,(Coords*1.0015) + 0.5).rgb*float3(0.0,0.0,0.8));
			Chro2 += (tex2D(CASampler,(Coords*1.001) + 0.5).rgb*float3(0.0,0.25,0.0));
			Chro2 += (tex2D(CASampler,(Coords*1.0025) + 0.5).rgb*float3(0.2,0.0,0.2));
			
		#endif
			
		#if CA_Width == 1
		
			Chro = (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.8,0.0,0.0));
			Chro += (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(0.0,0.25,0.0));
			
			Chro2 = (tex2D(CASampler,(Coords*1.003) + 0.5).rgb*float3(0.0,0.0,0.8));
			Chro2 += (tex2D(CASampler,(Coords*1.002) + 0.5).rgb*float3(0.0,0.25,0.0));
			Chro2 += (tex2D(CASampler,(Coords*1.0045) + 0.5).rgb*float3(0.2,0.0,0.2));
			
		#endif
			
		#if CA_Width == 2 
				
			Chro = (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.3,0.0,0.0));
			Chro += (tex2D(CASampler,(Coords*0.9965) + 0.5).rgb*float3(0.5,0.10,0.0));
			Chro += (tex2D(CASampler,(Coords*0.999) + 0.5).rgb*float3(0.0,0.15,0.0));
			
			Chro2 = (tex2D(CASampler,(Coords*1.005) + 0.5).rgb*float3(0.05,0.0,0.25));
			Chro2 += (tex2D(CASampler,(Coords*1.003) + 0.5).rgb*float3(0.0,0.10,0.55));
			Chro2 += (tex2D(CASampler,(Coords*1.001) + 0.5).rgb*float3(0.0,0.15,0.0));
			Chro2 += (tex2D(CASampler,(Coords*1.006) + 0.5).rgb*float3(0.15,0.0,0.2));
			
		#endif
			
		#if CA_Width == 3
			
			Chro = (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(0.15,0.0,0.0));
			Chro += (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.25,0.03,0.0));
			Chro += (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.4,0.07,0.0));
			Chro += (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(0.0,0.15,0.0));
			
			Chro2 = (tex2D(CASampler,(Coords*1.002) + 0.5).rgb*float3(0.0,0.12,0.40));
			Chro2 += (tex2D(CASampler,(Coords*1.004) + 0.5).rgb*float3(0.025,0.08,0.30));
			Chro2 += (tex2D(CASampler,(Coords*1.006) + 0.5).rgb*float3(0.05,0.05,0.20));
			Chro2 += (tex2D(CASampler,(Coords*1.008) + 0.5).rgb*float3(0.125,0.0,0.10));
			
		#endif 
			
		#if CA_Width == 4
			
			Chro = (tex2D(CASampler,(Coords*0.989) + 0.5).rgb*float3(0.15,0.0,0.0));
			Chro += (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(0.25,0.03,0.0));
			Chro += (tex2D(CASampler,(Coords*0.995) + 0.5).rgb*float3(0.4,0.07,0.0));
			Chro += (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(0.0,0.15,0.0));
			
			Chro2 = (tex2D(CASampler,(Coords*1.002) + 0.5).rgb*float3(0.0,0.12,0.40));
			Chro2 += (tex2D(CASampler,(Coords*1.005) + 0.5).rgb*float3(0.025,0.08,0.30));
			Chro2 += (tex2D(CASampler,(Coords*1.008) + 0.5).rgb*float3(0.05,0.05,0.20));
			Chro2 += (tex2D(CASampler,(Coords*1.011) + 0.5).rgb*float3(0.125,0.0,0.10));
			
		#endif 
	#endif
	
	#if CA_Color == 1
		#if CA_Width == 0
			
			Chro = (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(1.0,0.0,0.0));
			Chro = max(Chro, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
			Chro2 = (tex2D(CASampler,(Coords*1.002) + 0.5).rgb*float3(0.0,0.0,1.0));
			Chro2 = max(Chro2, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
		#endif
			
		#if CA_Width == 1
		
			Chro = (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(1.0,0.0,0.0));
			Chro = max(Chro, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
			Chro2 = (tex2D(CASampler,(Coords*1.004) + 0.5).rgb*float3(0.0,0.0,1.0));
			Chro2 = max(Chro2, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
		#endif
			
		#if CA_Width == 2 
				
			Chro = (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(1.0,0.0,0.0));
			Chro = max(Chro, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
			Chro2 = (tex2D(CASampler,(Coords*1.006) + 0.5).rgb*float3(0.0,0.0,1.0));
			Chro2 = max(Chro2, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
		#endif
			
		#if CA_Width == 3
			
			Chro = (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(1.0,0.0,0.0));
			Chro = max(Chro, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
			Chro2 = (tex2D(CASampler,(Coords*1.008) + 0.5).rgb*float3(0.0,0.0,1.0));
			Chro2 = max(Chro2, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
		#endif 
			
		#if CA_Width == 4
			
			Chro = (tex2D(CASampler,(Coords*0.989) + 0.5).rgb*float3(1.0,0.0,0.0));
			Chro = max(Chro, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
			Chro2 = (tex2D(CASampler,(Coords*1.011) + 0.5).rgb*float3(0.0,0.0,1.0));
			Chro2 = max(Chro2, tex2D(CASampler,(Coords) + 0.5).rgb)*0.5;
			
		#endif 
	#endif
	
	#if CA_Color == 2
		#if CA_Width == 0
			
			Chro = (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(1.0,0.0,0.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 1
		
			Chro = (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(1.0,0.0,0.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 2 
				
			Chro = (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(1.0,0.0,0.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 3
			
			Chro = (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(1.0,0.0,0.0));
			
			Chro2 = 0;
			
		#endif 
			
		#if CA_Width == 4
			
			Chro = (tex2D(CASampler,(Coords*0.989) + 0.5).rgb*float3(1.0,0.0,0.0));
			
			Chro2 = 0;
			
		#endif 
	#endif
	
	#if CA_Color == 3
		#if CA_Width == 0
			
			Chro = (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(0.0,0.0,1.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 1
		
			Chro = (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.0,0.0,1.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 2 
				
			Chro = (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.0,0.0,0.3));
			Chro += (tex2D(CASampler,(Coords*0.9965) + 0.5).rgb*float3(0.0,0.0,0.7));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 3
			
			Chro = (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(0.0,0.0,1.0));
			//Chro += (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.0,0.0,0.3));
			//Chro += (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.0,0.0,0.5));
			
			Chro2 = 0;
			
		#endif 
			
		#if CA_Width == 4
			
			Chro = (tex2D(CASampler,(Coords*0.989) + 0.5).rgb*float3(0.0,0.0,1.0));
			//Chro += (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.0,0.0,0.3));
			//Chro += (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.0,0.0,0.5));
			
			Chro2 = 0;
			
		#endif 
	#endif
	
	#if CA_Color == 4
		#if CA_Width == 0
			
			Chro = (tex2D(CASampler,(Coords*0.998) + 0.5).rgb*float3(1.0,0.0,1.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 1
		
			Chro = (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(1.0,0.0,1.0));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 2 
				
			Chro = (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(1.0,0.0,1.0));
			//Chro += (tex2D(CASampler,(Coords*0.9965) + 0.5).rgb*float3(0.0,0.0,0.7));
			
			Chro2 = 0;
			
		#endif
			
		#if CA_Width == 3
			
			Chro = (tex2D(CASampler,(Coords*0.992) + 0.5).rgb*float3(1.0,0.0,1.0));
			//Chro += (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.0,0.0,0.3));
			//Chro += (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.0,0.0,0.5));
			
			Chro2 = 0;
			
		#endif 
			
		#if CA_Width == 4
			
			Chro = (tex2D(CASampler,(Coords*0.989) + 0.5).rgb*float3(1.0,0.0,1.0));
			//Chro += (tex2D(CASampler,(Coords*0.994) + 0.5).rgb*float3(0.0,0.0,0.3));
			//Chro += (tex2D(CASampler,(Coords*0.996) + 0.5).rgb*float3(0.0,0.0,0.5));
			
			Chro2 = 0;
			
		#endif 
	#endif	
}

#if USE_ChromaticAberration == 1
#if Use_MotionBlurCA == 1 
float4 CA_PreviousPreviousFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
	return tex2D(CurrentSampler, texcoord);
}

void CA_PreviousFrame(float4 vpos : SV_Position, float2 texcoord : TEXCOORD, out float4 current : SV_Target0, out float4 previousprevious : SV_Target1)
{
	current = tex2D(RFX_backbufferColor, texcoord);
	previousprevious = tex2D(PrevSampler, texcoord);
}
#endif

float3 CA_RadialBlur(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float2 distance_xy = texcoord - float2(0.5,0.5);
	float2 center = distance_xy;
	distance_xy *= float2((RFX_pixelSize.y / RFX_pixelSize.x),CA_LensShape);
	float Concave = dot(distance_xy,distance_xy)*CA_LensFocus;
	Concave = (1.0 + pow(Concave,0.25) * -1.00);
	Concave = 2 - (Concave) * (0.01);
			
	float2 Coords = (Concave)*(center.xy*0.5);
	
	#if CA_Blurring == 0
	#define Samples 0
	#elif CA_Blurring == 1 
	#define Samples 3
	float weight[3] = {0.5, 0.3, 0.2};
	float sampleOffsets[3] = { 0.999, 0.998, 0.997 };
	float sampleOffsets2[3] = { 1.001, 1.002, 1.003 };
	#elif CA_Blurring == 2 
	#define Samples 5
	float weight[5] = { 0.2879768, 0.46703928, 0.2001597, 0.04120935, 0.003614855 };
	float sampleOffsets[5] = { 0.999, 0.998, 0.997, 0.996, 0.995 };
	float sampleOffsets2[5] = { 1.001, 1.002, 1.003, 1.004, 1.005 };
	#elif CA_Blurring == 3 
	#define Samples 11
	float weight[11] = {0.1486926, 0.1457586, 0.1372968, 0.1242738, 0.1080882, 0.0903366, 0.0725508, 0.055989, 0.0415188, 0.0295848, 0.0202572 };
	float sampleOffsets[11] = { 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.993, 0.992, 0.991, 0.990, 0.989 };
	float sampleOffsets2[11] = { 1.001, 1.002, 1.003, 1.004, 1.005, 1.006, 1.007, 1.008, 1.009, 1.010, 1.011 };
	#elif CA_Blurring == 4 
	#define Samples 21
	float weight[21] = { 0.082607, 0.081792, 0.080977, 0.0786265, 0.076276, 0.0726585, 0.069041, 0.064545, 0.060049, 0.055118, 0.050187, 0.0452465, 0.040306, 0.0357055, 0.031105, 0.0270855, 0.023066, 0.019751, 0.016436, 0.013845, 0.011254 };
	float sampleOffsets[21] = { 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.993, 0.992, 0.991, 0.990, 0.989, 0.988, 0.987,0.986, 0.985, 0.984, 0.983, 0.982, 0.981, 0.980, 0.979 };
	float sampleOffsets2[21] = { 1.001, 1.002, 1.003, 1.004, 1.005, 1.006, 1.007, 1.008, 1.009, 1.010, 1.011, 1.0012, 1.013, 1.014, 1.015, 1.016, 1.017, 1.018, 1.019, 1.020, 1.021 };
	#endif
	
	#if Samples > 0
	
	float3 color = tex2D(CAScaleSampler, texcoord).rgb*weight[0];
	#if CA_Color == 0 || CA_Color == 1
	float3 color2 = tex2D(caBlurSamplerPong, texcoord).rgb*weight[0];
	#endif
	
	[loop]
	for(int i = 1; i < Samples; ++i) {
		color += (tex2D(CAScaleSampler, (Coords*sampleOffsets[i])+0.5).rgb)*weight[i];
		#if CA_Color == 0 || CA_Color == 1
		color2 += (tex2D(caBlurSamplerPong, (Coords*sampleOffsets2[i])+0.5).rgb)*weight[i];
		#endif
		
	}
	#else 
	
	float3 color = tex2D(CAScaleSampler, texcoord).rgb;
	float3 color2 = tex2D(caBlurSamplerPong, texcoord).rgb;

	#endif
		float3 Orig = tex2D(RFX_backbufferColor, texcoord).rgb;
		
		#if CA_Color == 0
			color = (color+color2+(Orig*float3(0.0,0.5,0.0)));
		#elif CA_Color == 1
			color = (color+color2);
		#elif CA_Color == 2
			color = (color+(Orig*float3(0.0,1.0,1.0)));
		#elif CA_Color == 3
			color = (color+(Orig*float3(1.0,1.0,0.0)));
		#elif CA_Color == 4
			color = (color+(Orig*float3(0.0,1.0,0.0)));
		#endif
		
		float dist = dot(distance_xy,distance_xy)*CA_LensFocus;
		dist = (1.0 + pow(dist,0.25) * -1);
		
		color = lerp(color,Orig,smoothstep(0.0,1.0,dist));
		
		#if CA_RadialBlurring == 0
		float3 Chroma = color.rgb - dot(color.rgb,float3(0.25,0.5,0.25));
		float3 Luma = dot(Orig,float3(0.25,0.5,0.25));
		color.rgb = lerp(Luma+Chroma,color.rgb,RadialBlurStrength);
		#endif
		color = lerp(Orig,color,CA_Strength);
		//color = Concave;

	return color;
}
#if CA_RadialBlurring >= 1
float3 CA_RadialBlur2(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float2 distance_xy = texcoord - float2(0.5,0.5);
	float2 center = distance_xy;
	distance_xy *= float2((RFX_pixelSize.y / RFX_pixelSize.x),CA_LensShape);
	float Concave = dot(distance_xy,distance_xy)*CA_LensFocus;
	Concave = (1.0 + (pow(Concave,0.25) * -1.00));
	Concave = 2 - (Concave) * (0.01);
			
	float2 Coords = (Concave)*(center.xy*0.5);
	
	#if CA_RadialBlurring == 0
	#define Samples2 0
	#elif CA_RadialBlurring == 1 
	#define Samples2 3
	float weight[3] = {0.5, 0.3, 0.2};
	float sampleOffsets[3] = { 0.999, 0.998, 0.997 };
	float sampleOffsets2[3] = { 1.001, 1.002, 1.003 };
	#elif CA_RadialBlurring == 2 
	#define Samples2 5
	float weight[5] = { 0.2879768, 0.46703928, 0.2001597, 0.04120935, 0.003614855 };
	float sampleOffsets[5] = { 0.999, 0.998, 0.997, 0.996, 0.995 };
	#elif CA_RadialBlurring == 3 
	#define Samples2 11
	float weight[11] = {0.1486926, 0.1457586, 0.1372968, 0.1242738, 0.1080882, 0.0903366, 0.0725508, 0.055989, 0.0415188, 0.0295848, 0.0202572 };
	float sampleOffsets[11] = { 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.993, 0.992, 0.991, 0.990, 0.989 };
	#elif CA_RadialBlurring == 4 
	#define Samples2 21
	float weight[21] = { 0.082607, 0.081792, 0.080977, 0.0786265, 0.076276, 0.0726585, 0.069041, 0.064545, 0.060049, 0.055118, 0.050187, 0.0452465, 0.040306, 0.0357055, 0.031105, 0.0270855, 0.023066, 0.019751, 0.016436, 0.013845, 0.011254 };
	float sampleOffsets[21] = { 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.993, 0.992, 0.991, 0.990, 0.989, 0.988, 0.987,0.986, 0.985, 0.984, 0.983, 0.982, 0.981, 0.980, 0.979 };
	#endif
	
	float3 color = tex2D(caBlurSamplerPing, texcoord).rgb*weight[0];
	
	[loop]
	for(int i = 1; i < Samples2; ++i) {
		color += (tex2D(caBlurSamplerPing, (Coords*sampleOffsets[i])+0.5).rgb)*weight[i];	
	}
	
	float3 Orig = tex2D(RFX_backbufferColor, texcoord).rgb;
	float3 Chroma = color.rgb - dot(color.rgb,float3(0.25,0.5,0.25));
	float3 Luma = dot(Orig,float3(0.25,0.5,0.25));
	color.rgb = lerp(Luma+Chroma,color.rgb,RadialBlurStrength);
	
	float dist = dot(distance_xy,distance_xy)*CA_LensFocus;
	dist = (1.0 + pow(dist,0.25) * -1);
	//dist = clamp(dist,0.0,1.0);
		
	color = lerp(color,Orig,smoothstep(0.0,1.0,dist));
	
	return color;
}
#endif

#if Use_MotionBlurCA == 1
float4 CA_MotionBlur(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{			
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	float3 ChroBlur = tex2D(CurrentSampler, texcoord).rgb;
	float3 ChroBlur2 = tex2D(PrevSampler, texcoord).rgb;
	float3 ChroBlur3 = tex2D(PrevPrevSampler, texcoord).rgb;
	
	ChroBlur3 *= float3(1.0,0.0,0.0);
	ChroBlur2 *= float3(0.0,0.5,0.0);
	ChroBlur *= float3(0.0,0.5,0.0);
	float3 OrigBlur = color.rgb * float3(0.0,0.0,1.0);
	ChroBlur = ChroBlur+ChroBlur2+ChroBlur3+OrigBlur;
	
	color.rgb = lerp(color.rgb,ChroBlur,CA_BlurStrength);

	return color;
}
#endif
#endif
technique ChroAb <bool enabled = true; int toggle = ca_ToggleKey; >
{

	pass G 
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_Final;	
		RenderTarget0 = CAScale;
		RenderTarget1 = caBlurTex2Dpong;
	}
	
	pass G 
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_RadialBlur;
		#if CA_RadialBlurring >= 1
		RenderTarget = caBlurTex2Dping;
		#endif
	}
	
#if Use_MotionBlurCA == 1

	pass PrevColor
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_PreviousFrame;
		RenderTarget0 = CurrentTex;
		RenderTarget1 = PreviousPreviousTex;
	}
	
	pass caMB
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_MotionBlur;
	}
	
	pass CopyFrame
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_PreviousPreviousFrame;
		RenderTarget = PreviousTex;
	}
	
#endif
	
#if CA_RadialBlurring >= 1	
	pass G 
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = CA_RadialBlur2;
	}
#endif


}
#endif

#include "ReShade/ioFX.undef"

NAMESPACE_LEAVE()
